package com.nami.message.acl.repository.grphismsg;

import com.nami.message.domain.model.gmsg.GrpMsgDomain;
import com.nami.message.domain.repository.GrpHisMsgRepository;
import com.nami.message.core.mybatis.mapper.GrpHisMsgsMapper;
import com.nami.message.core.mybatis.dataobject.GrpHisMsgsDO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;


@Slf4j
@Component
@RequiredArgsConstructor
public class GrpHisMsgRepositoryImpl implements GrpHisMsgRepository {

    private final GrpHisMsgsMapper grpHisMsgsMapper;

    @Override
    public boolean add(GrpMsgDomain domain) {

        GrpHisMsgsDO grpHisMsgs = new GrpHisMsgsDO();
        grpHisMsgs.setMsgId(domain.getMessageId());
        grpHisMsgs.setAppKey(domain.getAppKey());

        grpHisMsgs.setSenderId(domain.getSenderId());
        grpHisMsgs.setConverId(domain.getCid());
        grpHisMsgs.setReceiverId(domain.getCid());

        grpHisMsgs.setPayload(domain.getPayload());
        grpHisMsgs.setPayloadType(domain.getPayloadType());
        grpHisMsgs.setSendTime(domain.getSendTime());
        grpHisMsgs.setConverType(2); // c2g

        grpHisMsgs.setSeq(domain.getSeq());

        grpHisMsgs.setMemberCount(0);

        grpHisMsgs.setMemberCount(domain.getReceiverCount());

        grpHisMsgs.setReadCount(0);

        grpHisMsgs.setDelFlag("0");
        grpHisMsgsMapper.insert(grpHisMsgs);

        return Boolean.TRUE;
    }

}
